package com.rdzn.mall.center.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.rdzn.mall.center.entity.PmsProduct;
import com.rdzn.mall.center.entity.SmsHomeNewProduct;
import com.rdzn.mall.center.mapper.SmsHomeNewProductMapper;
import com.rdzn.mall.center.service.IPmsProductService;
import com.rdzn.mall.center.service.ISmsHomeNewProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: sms_home_new_product
 * @Author: jeecg-boot
 * @Date:   2020-08-27
 * @Version: V1.0
 */
@DS("mall")
@Service
public class SmsHomeNewProductServiceImpl extends ServiceImpl<SmsHomeNewProductMapper, SmsHomeNewProduct> implements ISmsHomeNewProductService {

    @Autowired
    private IPmsProductService productService;

    @Override
    public List<PmsProduct> getList() {
        List<SmsHomeNewProduct> list = list(new LambdaQueryWrapper<SmsHomeNewProduct>().eq(SmsHomeNewProduct::getRecommendStatus, 1).orderByDesc(SmsHomeNewProduct::getSort));
        if (CollectionUtils.isNotEmpty(list)){
            List<Integer> ids = list.stream().map(SmsHomeNewProduct::getProductId).collect(Collectors.toList());
            return productService.getByIds(ids);
        }
        return null;
    }

}
